import { append } from 'ramda';

import { fill{{ pascalCase name }}ListQuery, {{ camelCase name }}Factory } from '../../../../mocks/factories';
import { renderHook } from '../../../../tests/utils/rendering';
import { use{{ pascalCase name }} } from '../use{{ pascalCase name }}.hook';

const item = {{ camelCase name }}Factory();
const items = [{{ camelCase name }}Factory(), item, {{ camelCase name }}Factory()];

describe('use{{ pascalCase name }}: Hook', () => {
  it('should return item value from query', async () => {
    const listMock = fill{{ pascalCase name }}ListQuery(items);
    const render = () => renderHook(() => use{{ pascalCase name }}(item.id), { apolloMocks: append(listMock) });

    const { result, waitForApolloMocks } = render();
    await waitForApolloMocks();

    expect(result.current.itemData).toEqual(item);
  });

  it('should not return non existing item from query', async () => {
    const listMock = fill{{ pascalCase name }}ListQuery([]);
    const render = () => renderHook(() => use{{ pascalCase name }}(item.id), { apolloMocks: append(listMock) });

    const { result, waitForApolloMocks } = render();
    await waitForApolloMocks();

    expect(result.current.itemData).toBeUndefined();
  });
});
